package com.djl.util;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * 用于加载资源文件
 */
public class PropertiesUtil {

    private static final Properties PROPERTIES = new Properties();


    /**
     * 获取
     * @param targetResource 目标资源 spring.properties
     * @param resourceField  资源属性 basePackage
     * @return
     */
    public static String getPackageScan(String targetResource,String resourceField){
        String basePackage = "";
        try {
            InputStream pathInput = PropertiesUtil.class.getClassLoader().getResourceAsStream(targetResource);
            PROPERTIES.load(pathInput);
            basePackage = PROPERTIES.getProperty(resourceField);
        } catch (IOException e) {
            e.printStackTrace();
        }
        if(null == basePackage || "".equals(basePackage)){
            throw new RuntimeException("未查询到资源路径:"+ targetResource+" 属性："+resourceField);
        }
        return basePackage;
    }

}
